package com.yookey.common.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yookey.common.constant.ResponseMessageEnum;
import com.yookey.common.exception.BusinessException;

import java.util.List;

/**
 * className AssertUtil
 */
public class AssertUtil {
    /**
     * 抛出异常
     *
     * @param responseMessageEnum
     */
    public static void throwException(ResponseMessageEnum responseMessageEnum) {
        throw new BusinessException(responseMessageEnum);
    }

    /**
     * 抛出异常
     *
     * @param responseMessageEnum
     */
    public static void throwException(ResponseMessageEnum responseMessageEnum, Object... params) {
        throw new BusinessException(responseMessageEnum, params);
    }

    /**
     * 抛出异常
     */
    public static void throwException(String code, String message) {
        throw new BusinessException(code, message);
    }

    /**
     * 抛出异常
     */
    public static void throwException(String code, Object... params) {
        throw new BusinessException(code, params);
    }

    /**
     * 字符串是否为空白 空白的定义如下： <br>
     * 1、为null <br>
     * 2、为不可见字符（如空格）<br>
     * 3、""<br>
     *
     * @param str     被检测的字符串
     * @param message 返回消息
     * @return 是否为空
     */
    public static void isBlank(String str, String message) {
        if (StrUtil.isBlank(str)) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    public static void isBlank(String str, ResponseMessageEnum responseMessageEnum) {
        if (StrUtil.isBlank(str)) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断对象为null值
     *
     * @param object
     * @param message
     */
    public static void isNull(Object object, String message) {
        if (ObjectUtil.isNull(object)) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断对象为null值
     *
     * @param object
     * @param message
     * @param responseMessageEnum
     */
    public static void isNull(Object object, ResponseMessageEnum responseMessageEnum, Object message) {
        if (ObjectUtil.isNull(object)) {
            throw new BusinessException(responseMessageEnum, message);
        }
    }


    /**
     * 判断对象为null值
     *
     * @param object
     */
    public static void isNull(Object object) {
        if (ObjectUtil.isNull(object)) {
            throw new BusinessException(ResponseMessageEnum.NULL_ERROR.getMessageKey());
        }
    }

    /**
     * 判断对象为null值
     *
     * @param object
     * @param responseMessageEnum
     */
    public static void isNull(Object object, ResponseMessageEnum responseMessageEnum) {
        if (ObjectUtil.isNull(object)) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断对象不为null值
     *
     * @param object
     * @param message
     */
    public static void isNotNull(Object object, String message) {
        if (ObjectUtil.isNotNull(object)) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断对象不为null值
     *
     * @param object
     * @param responseMessageEnum
     */
    public static void isNotNull(Object object, ResponseMessageEnum responseMessageEnum) {
        if (ObjectUtil.isNotNull(object)) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断对象不为null值
     *
     * @param object
     * @param responseMessageEnum
     * @param message
     */
    public static void isNotNull(Object object, ResponseMessageEnum responseMessageEnum, Object message) {
        if (ObjectUtil.isNotNull(object)) {
            throw new BusinessException(responseMessageEnum, message);
        }
    }

    /**
     * 集合是否为空
     *
     * @param list    集合
     * @param message 返回消息
     * @return 是否为空
     */
    public static void isCollEmpty(List<?> list, String message) {
        if (CollUtil.isEmpty(list)) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 集合是否为空
     *
     * @param list 集合
     * @return 是否为空
     */
    public static void isCollEmpty(List<?> list) {
        if (CollUtil.isEmpty(list)) {
            throw new BusinessException(ResponseMessageEnum.NULL_ERROR.getMessageKey());
        }
    }

    /**
     * 集合是否为空
     *
     * @param list
     * @param responseMessageEnum
     */
    public static void isCollEmpty(List<?> list, ResponseMessageEnum responseMessageEnum) {
        if (CollUtil.isEmpty(list)) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断int>0
     *
     * @param num
     * @param message
     */
    public static void isGtZeroNum(Integer num, String message) {
        if (num > 0) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断int>=0
     *
     * @param num
     * @param message
     */
    public static void isGtEqZeroNum(Integer num, String message) {
        if (ObjectUtil.isNotNull(num) && num >= 0) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断int>0
     *
     * @param num
     * @param responseMessageEnum
     */
    public static void isGtZeroNum(Integer num, ResponseMessageEnum responseMessageEnum) {
        if (num > 0) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断 false
     *
     * @param num
     * @param message
     * @param responseMessageEnum
     */
    public static void isGtZeroNum(Integer num, ResponseMessageEnum responseMessageEnum,Object... message) {
        if (num > 0) {
            throw new BusinessException(responseMessageEnum, message);
        }
    }

    /**
     * 判断int<=0
     *
     * @param num
     */
    public static void isLtEqZeroNum(Integer num) {
        if (ObjectUtil.isNotNull(num) && num <= 0) {
            throw new BusinessException(ResponseMessageEnum.BUSINESS_ERROR);
        }
    }


    /**
     * 判断long<=0
     *
     * @param num
     * @param message
     */
    public static void isLtEqZeroLong(Long num, String message) {
        if (ObjectUtil.isNotNull(num) && num <= 0) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断long<=0
     *
     * @param num
     * @param responseMessageEnum
     */
    public static void isLtEqZeroLong(Long num, ResponseMessageEnum responseMessageEnum) {
        if (ObjectUtil.isNotNull(num) && num <= 0) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断 false
     *
     * @param
     * @param
     */
    public static void isFalse(Boolean value) {
        if (!value) {
            throw new BusinessException(ResponseMessageEnum.BUSINESS_ERROR);
        }
    }

    /**
     * 判断 false
     *
     * @param
     * @param
     */
    public static void isFalse(Boolean value, String message) {
        if (!value) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }

    /**
     * 判断 false
     *
     * @param value
     * @param responseMessageEnum
     */
    public static void isFalse(Boolean value, ResponseMessageEnum responseMessageEnum) {
        if (!value) {
            throw new BusinessException(responseMessageEnum);
        }
    }

    /**
     * 判断 false
     *
     * @param value
     * @param message
     * @param responseMessageEnum
     */
    public static void isFalse(Boolean value, ResponseMessageEnum responseMessageEnum, Object message) {
        if (!value) {
            throw new BusinessException(responseMessageEnum, message);
        }
    }

    /**
     * 判断 true
     *
     * @param
     * @param
     */
    public static void isTrue(Boolean value) {
        if (value) {
            throw new BusinessException(ResponseMessageEnum.BUSINESS_ERROR);
        }
    }


    /**
     * 判断 true
     *
     * @param
     * @param
     */
    public static void isTrue(Boolean value, String message) {
        if (value) {
            throw new BusinessException(ResponseMessageEnum.VERIFY_ERROR.getMessageKey(), message);
        }
    }


    /**
     * 判断 true
     *
     * @param value
     * @param message
     * @param responseMessageEnum
     */
    public static void isTrue(Boolean value, ResponseMessageEnum responseMessageEnum, Object message) {
        if (value) {
            throw new BusinessException(responseMessageEnum, message);
        }
    }

    /**
     * 判断 true
     *
     * @param value
     * @param responseMessageEnum
     */
    public static void isTrue(Boolean value, ResponseMessageEnum responseMessageEnum) {
        if (value) {
            throw new BusinessException(responseMessageEnum);
        }
    }
}
